package com.meida.student.app.common.handler;


import com.meida.common.base.entity.EntityMap;
import com.meida.common.base.utils.FlymeUtils;
import com.meida.common.mybatis.interceptor.IndexInterceptor;
import com.meida.common.mybatis.interceptor.PageInterceptor;
import com.meida.common.mybatis.model.PageParams;
import com.meida.common.mybatis.query.CriteriaQuery;
import com.meida.module.bus.client.entity.BusInternationalCode;
import com.meida.module.bus.provider.service.AppUserMineService;
import com.meida.module.pay.client.entity.PayBalance;
import com.meida.module.pay.provider.service.PayBalanceService;
import com.meida.module.user.client.entity.AppSchool;
import com.meida.module.user.client.entity.AppUser;
import com.meida.module.user.provider.service.AppSchoolService;
import com.meida.module.user.provider.service.AppUserService;
import com.meida.module.user.provider.service.SysSliderService;
import com.meida.msg.provider.service.MsgReceiveService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 首页接口逻辑
 *
 * @author zyf
 */
@Component
@AllArgsConstructor
public class AppIndexHandler implements IndexInterceptor {


    private final AppUserService appUserService;

    private final AppSchoolService schoolService;

    private final PayBalanceService payBalanceService;

    private final MsgReceiveService msgReceiveService;

    private final SysSliderService sliderService;

    @Override
    public EntityMap complete(EntityMap entityMap, Long userId) {
        AppUser appUser = appUserService.getUserById(userId);
        if (FlymeUtils.isNotEmpty(appUser)) {
            entityMap.put("nickName", appUser.getNickName());
            String schoolId = appUser.getSchoolId();
            if (FlymeUtils.isNotEmpty(schoolId)) {
                AppSchool school = schoolService.getById(schoolId);
                //学校名称
                entityMap.put("schoolName", school.getSchoolName());
            }
            //学校ID
            entityMap.put("schoolId", schoolId);
            PayBalance payBalance = payBalanceService.addUserBalance(userId);
            //账户余额
            entityMap.put("balanceAmount", payBalance.getBindAmount());
            Long noReadMsgNum = msgReceiveService.countNoRead(userId);
            //未读消息
            entityMap.put("noReadMsgNum", noReadMsgNum);

            //上传试题轮播
            List<EntityMap> scstSlider = sliderService.listBySliderType(4);

            entityMap.put("scstSlider", scstSlider);

            //拍照提问图片
            EntityMap pztwSlider = sliderService.getOneBySliderType(5);

            entityMap.put("pztwImg", pztwSlider.get("sliderImg"));
            //预约辅导图片
            EntityMap yyfdSlider = sliderService.getOneBySliderType(6);

            entityMap.put("yyfdImg", yyfdSlider.get("sliderImg"));
            //作业无忧图片
            EntityMap zywySlider = sliderService.getOneBySliderType(7);
            entityMap.put("zywyImg", zywySlider.get("sliderImg"));

        }
        return entityMap;
    }
}
